﻿using BigEgg.Framework.Foundation;
using BigEgg.Framework.UnitTesting;
using FMStudio.Domain.Properties;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Globalization;

namespace FMStudio.Domain.SQLite.Test
{
    [TestClass]
    public class AuditTypeTest
    {
        [TestMethod]
        public void GeneralAuditTypeTest()
        {
            AuditType auditType = new AuditType();

            Assert.IsNotNull(auditType.ID);
            Assert.AreEqual("", auditType.Name);
            Assert.IsNull(auditType.PayType);

            PayType payType = new PayType();
            auditType.PayType = payType;
            auditType.Name = "Cash";

            Assert.AreEqual("", auditType.Validate());
        }

        [TestMethod]
        public void AuditTypePayTypePropertyChangedTest()
        {
            AuditType auditType = new AuditType();
            Assert.IsNull(auditType.PayType);

            PayType payType = new PayType();
            AssertHelper.PropertyChangedEvent(auditType, x => x.PayType, () => auditType.PayType = payType);
            Assert.AreEqual(payType, auditType.PayType);
        }
        
        [TestMethod]
        public void AuditTypeNameValidationTest()
        {
            AuditType auditType = new AuditType();

            Assert.AreEqual(string.Empty, auditType.Name);
            Assert.AreEqual(Resources.AuditTypeNameMandatory, auditType.Validate("Name"));

            auditType.Name = TestHelper.CreateString('A', 99);
            Assert.AreEqual("", auditType.Validate("Name"));
            auditType.Name = TestHelper.CreateString('A', 100);
            Assert.AreEqual("", auditType.Validate("Name"));
            auditType.Name = TestHelper.CreateString('A', 101);
            Assert.AreEqual(
                string.Format(CultureInfo.CurrentCulture, Resources.AuditTypeNameMaxLength, "Name", 100)
                , auditType.Validate("Name"));
        }

        [TestMethod]
        public void AuditTypePayTypeValidationTest()
        {
            AuditType AuditType = new AuditType();

            Assert.IsNull(AuditType.PayType);
            Assert.AreEqual(Resources.PayTypeMandatory, AuditType.Validate("PayType"));

            PayType payType = new PayType();
            AuditType.PayType = payType;
            Assert.AreEqual("", AuditType.Validate("PayType"));
        }
    }
}
